# -*- coding: utf-8 -*-
"""
@Time ： 2021/12/9 14:08
@Auth ： 颜
@File ：app.py
@IDE ：PyCharm
"""
from flask import Flask, render_template, request
import sqlite3
from page_utils import Pagination

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/home')
def home():
    return index()


@app.route('/movie')
def movie():
    datalist = []
    # li = []
    # for i in range(1, 100):
    #     li.append(i)

    # return render_template("test/test.html", index_list=index_list, html=html)
    db = sqlite3.connect('douban.db')
    cur = db.cursor()
    # '''select * from table limit (3-1)*10,10;'''
    sql = 'SELECT * FROM DOUBAN_DEMO; '
    data = cur.execute(sql)
    for item in data:
        # print(item)
        datalist.append(item)
    pager_obj = Pagination(request.args.get("page", 1), len(datalist), request.path, request.args,
                           per_page_count=10)
    # print(request.path)
    # print(request.args)
    index_list = datalist[pager_obj.start:pager_obj.end]
    html = pager_obj.page_html()
    cur.close()
    db.close()
    return render_template('movie.html', index_list=index_list, html=html)


@app.route('/score')
def score():
    score = []
    num = []
    db = sqlite3.connect('douban.db')
    cur = db.cursor()
    sql = 'select socre,count(socre) from DOUBAN_DEMO group by socre'
    data = cur.execute(sql)
    for item in data:
        # print(item)
        score.append(item[0])
        num.append(item[1])
    cur.close()
    db.close()
    return render_template('score.html', score=score, num=num)


@app.route('/world')
def world():
    return render_template('world.html')


@app.route('/team')
def team():
    return render_template('team.html')


if __name__ == '__main__':
    app.run(debug=True)
